From 4f8f288163a0ae8ba8b6e05abb2df52566c8e464 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sat, 1 Nov 2008 04:15:14 +0000 Subject: [PATCH] =?utf8?q?Bug=20412134=20=E2=80=93=20Add=20API=20to=20quer?= =?utf8?q?y=20style=20properties=20from=20the=20style?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 2008-11-01 Matthias Clasen Bug 412134 – Add API to query style properties from the style * gtk/gtk.symbols: * gtk/gtkstyle.[hc]: Add getters for style properties to avoid the need for ugly workarounds with dummy widget instances. Patch by Mariano Suárez-Alvarez svn path=/trunk/; revision=21744 --- ChangeLog | 9 ++ docs/reference/ChangeLog | 4 + docs/reference/gtk/gtk-sections.txt | 3 + gtk/gtk.symbols | 3 + gtk/gtkstyle.c | 142 ++++++++++++++++++++++++++++ gtk/gtkstyle.h | 13 +++ 6 files changed, 174 insertions(+) diff --git a/ChangeLog b/ChangeLog index c7659244cc..e2ba9b3e49 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2008-11-01 Matthias Clasen + + Bug 412134 – Add API to query style properties from the style + + * gtk/gtk.symbols: + * gtk/gtkstyle.[hc]: Add getters for style properties to + avoid the need for ugly workarounds with dummy widget instances. + Patch by Mariano Suárez-Alvarez + 2008-10-31 Christian Dywan Bug 558667 – gtk_font_selection_dialog_get_apply_button - deprecate? diff --git a/docs/reference/ChangeLog b/docs/reference/ChangeLog index ae48ef8f8f..1379d62fdc 100644 --- a/docs/reference/ChangeLog +++ b/docs/reference/ChangeLog @@ -1,3 +1,7 @@ +2008-11-01 Matthias Clasen + + * gtk/gtk-sections.txt: Add new GtkStyle functions. + 2008-10-29 Federico Mena Quintero * gtk/drawing-model.xml: New chapter for "The GTK+ Drawing Model". diff --git a/docs/reference/gtk/gtk-sections.txt b/docs/reference/gtk/gtk-sections.txt index 631e696d11..f073ddf7d2 100644 --- a/docs/reference/gtk/gtk-sections.txt +++ b/docs/reference/gtk/gtk-sections.txt @@ -5699,6 +5699,9 @@ gtk_style_lookup_icon_set gtk_style_render_icon gtk_style_get_font gtk_style_set_font +gtk_style_get_property +gtk_style_get_valist +gtk_style_get gtk_draw_hline gtk_draw_vline gtk_draw_shadow diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols index ca24e372b9..bd22e24b92 100644 --- a/gtk/gtk.symbols +++ b/gtk/gtk.symbols @@ -1227,6 +1227,9 @@ gtk_style_new gtk_style_render_icon gtk_style_set_background gtk_draw_insertion_cursor +gtk_style_get_property +gtk_style_get_valist +gtk_style_get #endif #endif diff --git a/gtk/gtkstyle.c b/gtk/gtkstyle.c index d913a7a5e3..c2fb0813cf 100644 --- a/gtk/gtkstyle.c +++ b/gtk/gtkstyle.c @@ -28,6 +28,7 @@ #include #include #include +#include #include "gtkgc.h" #include "gtkmarshalers.h" #undef GTK_DISABLE_DEPRECATED @@ -1696,6 +1697,147 @@ style_property_values_cmp (gconstpointer bsearch_node1, return val1->widget_type < val2->widget_type ? -1 : 1; } +/** + * gtk_style_get_property: + * @style: a #GtkStyle + * @widget_type: the #GType of a descendant of #GtkWidget + * @property_name: the name of the style property to get + * @value: a #GValue where the value of the property being + * queried will be stored + * + * Queries the value of a style property corresponding to a + * widget class is in the given style. + * + * Since: 2.16 + */ +void +gtk_style_get_property (GtkStyle *style, + GType widget_type, + const gchar *property_name, + GValue *value) +{ + GtkWidgetClass *klass; + GParamSpec *pspec; + GtkRcPropertyParser parser; + const GValue *peek_value; + + klass = g_type_class_peek (widget_type); + pspec = gtk_widget_class_find_style_property (klass, property_name); + + if (!pspec) + { + g_warning ("%s: widget class `%s' has no property named `%s'", + G_STRLOC, + g_type_name (widget_type), + property_name); + return; + } + + parser = g_param_spec_get_qdata (pspec, + g_quark_from_static_string ("gtk-rc-property-parser")); + + peek_value = _gtk_style_peek_property_value (style, widget_type, pspec, parser); + + if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec)) + g_value_copy (peek_value, value); + else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value))) + g_value_transform (peek_value, value); + else + g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'", + pspec->name, + g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)), + G_VALUE_TYPE_NAME (value)); +} + +/** + * gtk_style_get_valist: + * @style: a #GtkStyle + * @widget_type: the #GType of a descendant of #GtkWidget + * @first_property_name: the name of the first style property to get + * @var_list: a va_list of pairs of property names and + * locations to return the property values, starting with the + * location for @first_property_name. + * + * Non-vararg variant of gtk_style_get(). + * Used primarily by language bindings. + * + * Since: 2.16 + */ +void +gtk_style_get_valist (GtkStyle *style, + GType widget_type, + const gchar *first_property_name, + va_list var_args) +{ + const char *property_name; + GtkWidgetClass *klass; + + g_return_if_fail (GTK_IS_STYLE (style)); + + klass = g_type_class_ref (widget_type); + + property_name = first_property_name; + while (property_name) + { + GParamSpec *pspec; + GtkRcPropertyParser parser; + const GValue *peek_value; + gchar *error; + + pspec = gtk_widget_class_find_style_property (klass, property_name); + + if (!pspec) + { + g_warning ("%s: widget class `%s' has no property named `%s'", + G_STRLOC, + g_type_name (widget_type), + property_name); + break; + } + + parser = g_param_spec_get_qdata (pspec, + g_quark_from_static_string ("gtk-rc-property-parser")); + + peek_value = _gtk_style_peek_property_value (style, widget_type, pspec, parser); + G_VALUE_LCOPY (peek_value, var_args, 0, &error); + if (error) + { + g_warning ("%s: %s", G_STRLOC, error); + g_free (error); + break; + } + + property_name = va_arg (var_args, gchar*); + } + + g_type_class_unref (klass); +} + +/** + * gtk_style_get: + * @style: a #GtkStyle + * @widget_type: the #GType of a descendant of #GtkWidget + * @first_property_name: the name of the first style property to get + * @Varargs: pairs of property names and locations to + * return the property values, starting with the location for + * @first_property_name, terminated by %NULL. + * + * Gets the values of a multiple style properties for @widget_type + * from @style. + */ +void +gtk_style_get (GtkStyle *style, + GType widget_type, + const gchar *first_property_name, + ...) +{ + va_list var_args; + + va_start (var_args, first_property_name); + gtk_style_get_valist (style, widget_type, first_property_name, var_args); + va_end (var_args); +} + const GValue* _gtk_style_peek_property_value (GtkStyle *style, GType widget_type, diff --git a/gtk/gtkstyle.h b/gtk/gtkstyle.h index bef5c2bb83..2b7d66734c 100644 --- a/gtk/gtkstyle.h +++ b/gtk/gtkstyle.h @@ -863,6 +863,19 @@ GtkBorder *gtk_border_new (void) G_GNUC_MALLOC; GtkBorder *gtk_border_copy (const GtkBorder *border_); void gtk_border_free (GtkBorder *border_); +void gtk_style_get_property (GtkStyle *style, + GType widget_type, + const gchar *property_name, + GValue *value); +void gtk_style_get_valist (GtkStyle *style, + GType widget_type, + const gchar *first_property_name, + va_list var_args); +void gtk_style_get (GtkStyle *style, + GType widget_type, + const gchar *first_property_name, + ...) G_GNUC_NULL_TERMINATED; + /* --- private API --- */ const GValue* _gtk_style_peek_property_value (GtkStyle *style, GType widget_type, -- 2.30.2